package com.sy.api;

/**
 * @className: CourseTypesController
 * @author: Mr.Liu
 * @date: 2025/10/29 14:37
 * @Version: 1.0
 * @description:
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sy.ResultVO;
import com.sy.pojo.CourseTypes;
import com.sy.service.CourseTypesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.models.security.SecurityScheme;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/api/courseTypes")
@Tag(name = "课程类型管理模块")
@Slf4j
public class CourseTypesController {
    @Resource
    private CourseTypesService courseTypesService;
    @GetMapping("/add")
    @Operation(summary = "添加类型")
    public ResultVO<Object> add(String name) {
        log.info("添加的入参:{}",name);
        CourseTypes courseTypes = CourseTypes.builder()
                .name(name)
                .status(1)
                .createTime(LocalDateTime.now())
                .build();
        boolean flag = courseTypesService.save(courseTypes);
        return flag?ResultVO.success():ResultVO.error();
    }
    @GetMapping("/checkNameUnique")
    @Operation(summary = "校验课程类名名称")
    public ResultVO<Boolean> checkName(String name) {
        log.info("校验课程类型名称的入参:{}",name);
        boolean flag = courseTypesService.queryBeanByName(name);
        return ResultVO.success(flag);
    }
    @GetMapping("/list")
    @Operation(summary = "查询全部课程类别")
    public ResultVO<List<CourseTypes>> queryList() {
        log.info("处理查询所有课程类别信息请求");
        return ResultVO.success(courseTypesService.list());
    }
    @GetMapping("/updateName")
    @Operation(summary = "更新课程类别名称")
    public ResultVO<Object> updateName(@RequestParam Map<String,Object> map) {
        log.info("更改的课程类型名称:{},{}",map.get("id"),map.get("name"));
        boolean flag = courseTypesService.updateName(map);
        return flag?ResultVO.success():ResultVO.error();
    }
    @GetMapping("/updateStatus")
    @Operation(summary = "更新课程类别状态")
    public ResultVO<Object> updateStatus(@RequestParam Map<String,Object> map) {
        log.info("更改的状态参数:{},{}",map.get("id"),map.get("status"));
        boolean flag = courseTypesService.updateStatus(map);
        return flag?ResultVO.success():ResultVO.error();
    }
    /*
     * @Author Mr.Liu
     * @Description //TODO 查询可用类别
     * @Date 11:06 2025/11/6
     * @Param []
     * @return com.sy.ResultVO<java.lang.Object>
     **/
    @GetMapping("/listByStatus")
    @Operation(summary = "查询可用类别")
    public ResultVO<Object> queryByStatus() {
        return ResultVO.success(courseTypesService.queryByStatus());
    }

}
